//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.xnx3.wangmarket.plugin.htmlVisualEditor.controller;

import com.xnx3.j2ee.pojo.vo.UploadFileVO;
import com.xnx3.j2ee.service.SqlService;
import com.xnx3.j2ee.util.AttachmentUtil;
import com.xnx3.wangmarket.customer.controller.BaseController;
import com.xnx3.wangmarket.customer.entity.Site;
import com.xnx3.wangmarket.customer.service.SiteService;
import com.xnx3.wangmarket.customer.util.ActionLogUtil;
import com.xnx3.wangmarket.customer.util.SiteUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping({"/plugin/HtmlVisualEditor/"})
public class HtmlVisualEditorPluginController extends BaseController {
    @Resource
    private SqlService sqlService;
    @Resource
    private SiteService siteService;

    public HtmlVisualEditorPluginController() {
    }

    @RequestMapping(
        value = {"uploadFile.json"},
        method = {RequestMethod.POST}
    )
    @ResponseBody
    public UploadFileVO uploadFile(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
        UploadFileVO uploadFileVO = new UploadFileVO();
        Site site = this.getSite();
        if (site == null) {
            uploadFileVO.setBaseVO(0, "请先登录");
            return uploadFileVO;
        } else if (!SiteUtil.isUploadFile(site)) {
            uploadFileVO.setBaseVO(0, "空间占用超出，已不允许上传");
            return uploadFileVO;
        } else {
            uploadFileVO = AttachmentUtil.uploadImageByMultipartFile("site/" + this.getSiteId() + "/templateimage/", file);
            if (uploadFileVO.getResult() == 1) {
                ActionLogUtil.insert(request, "Plugin HtmlVisualEditor 上传图片", uploadFileVO.getName());
            }

            return uploadFileVO;
        }
    }
}
